package com.fingard.dsp.bank.directConfig;

import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;

import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ActSetItem {
	public String actATS = "";
	
	/** 交易类型 */
	public String forTrg = "";
	
	/** 企业编码 */
	public String corpCode = "";
	
	/** 地区号 */
	public String areaCode = "";
	
	/** 映射后的账号，空则直接用ATS的，用于ATS账号与第三方虚拟户不一致的情况 */
	public String actMapped = "";
	
	public String cnapsCode = "";// 开户行号
	
	/** 用户名 */
	public String userCode = "";

	/** 用户密码 */
	public String userFlag = "";

	/** 公众账号ID */
	public String appId = "";

	/** 商户号 */
	public String merchantId = "";

    /** 子公众账号ID */
    public String subAppId = "";

    /** 子商户号 */
    public String subMerchantId = "";

	/** 虚拟账号 */
	public String virtualAct;

	/** 内部商户号 */
	public String inMerchantId = "";

	/** 终端号 */
	public String termId = "";

	/** 终端IP */
	public String createIP = "";

	public String batType = "";// 类型

	/** 本方（商户）私钥证书路径，.key */
	public String ownKeyStorePath = "";

	/** 本方（商户）私钥证书密码 */
	public String ownKeyPassword = "";

	/** 本方（商户）证书路径 .p12*/
	public String ownCertFilePath = "";

	/** 对方（渠道方）公钥证书路径 */
	public String oppCertFilePath = "";

	/** API密钥或安全码，用于加入到明文的最后，生成摘要（签名） */
	public String saltKey = "";

	/** 后台异步通知地址 */
	public String notifyURL = "";

	/** 前台同步通知地址 */
	public String returnURL = "";

	/** 交易服务地址 */
	public String serverURL = "";

	/** 对账单获取地址 */
	public String qryStatementURL = "";

	/** 重新发起订单请求地址 */
	public String resendURL;

	public String bank = "";

	/** 扣款协议号 */
	public String recAgNum = "";

	public String appSecret = "";

	/** 业务代码 */
	public String busCode = "";

	/** 限制金额 */
	public String amtLimit = "";

	/** ftp服务器路径 */
	public String ftpPath = "";

	/** 产品编码 */
	public String goodNo = "";

	/** POS通知地址 */
	public String posNoticeUrl = "";

	/** 退款-后台通知地址 */
	public String refundNotifyURL = "";

	/** pos退款-后台通知地址 */
	public String posRefundNotifyURL = "";

	/** 合作伙伴ID */
	public String pid = "";

	/** 签名方式 */
	public String signType = "";

	/** webapi商户私钥证书路径 */
	public String ownKeyWebAPIStorePath = "";

	/** webapi融汇公钥证书路径 */
	public String oppCertWebAPIFilePath = "";

	/** webapi密钥 */
	public String webAPISercretKey = "";

	/** webapi后台通知地址 */
	public String webAPINotifyUrl = "";

	/** 支付宝授权码 */
	public String appAuthToken = "";

	/** appKey */
	public String appKey = "";

    /**
     * 对账单类型(S-收、F-付、*-全部)
     */
	public String billType = "";

    /**
     * 渠道方用户ID
     */
	public String sellerId = "";

    /**
     * 支付宝公钥证书文件路径
     */
	public String alipayPublicCertPath = "";

    /**
     * 支付宝CA根证书文件路径
     */
	public String rootCertPath = "";

	/**
	 * 商家身份ID唯一标识
	 */
	public String identity = "";

    /**
     * 对账单通讯请求方式(get/post)
     */
	public String billRequestType = "";

	/**
	 * webapi后台通知地址
	 */
	public Map<String, String> busCodeMap = new ConcurrentHashMap<String, String>();

	public Map<String, String> serverURLMap = new ConcurrentHashMap<String, String>();

    public Map<String, String> notifyURLMap = new ConcurrentHashMap<String, String>();

    public Map<String, String> saltKeyMap = new ConcurrentHashMap<String, String>();

	public Map<String, String> appIdMap = new ConcurrentHashMap<String, String>();

	public Map<String, String> appSecretMap = new ConcurrentHashMap<String, String>();

	public void fromXElement(XElement p_xe) throws Exception {
		actATS = p_xe.getAttrValue("actATS");
		forTrg = p_xe.getAttrValue("for");
		/*
		 * if(StringHelper.isNullOrEmpty(forTrg)){ forTrg = "*"; }
		 */
		actMapped = p_xe.getSingleText("actMapped");
		if (StringHelper.isNullOrEmpty(actMapped)) {
			actMapped = actATS;
		}
		corpCode = p_xe.getSingleTextNotNull("corpCode").replaceAll("\r|\n|\t", "");
		cnapsCode = p_xe.getSingleTextNotNull("cnapsCode").replaceAll("\r|\n|\t", "");
		areaCode = p_xe.getSingleTextNotNull("areaCode").replaceAll("\r|\n|\t", "");
		userCode = p_xe.getSingleTextNotNull("userCode").replaceAll("\r|\n|\t", "");
		userFlag = p_xe.getSingleTextNotNull("userFlag").replaceAll("\r|\n|\t", "");
		appId = p_xe.getSingleTextNotNull("appId").replaceAll("\r|\n|\t", "");
		ArrayList<XElement> appIdList = p_xe.getChildList("appId");
		if (appIdList != null) {
			for (XElement c_xe : appIdList) {
				String p_for = c_xe.getAttrValue("for");
				appIdMap.put(p_for, c_xe.innerText);
			}
		}
		serverURL = p_xe.getSingleTextNotNull("serverURL").replaceAll("\r|\n|\t", "");
		ArrayList<XElement> serverURLList = p_xe.getChildList("serverURL");
		if (serverURLList != null) {
			for (XElement c_xe : serverURLList) {
				String p_for = c_xe.getAttrValue("for");
				serverURLMap.put(p_for, c_xe.innerText);
			}
		}
        subAppId = p_xe.getSingleTextNotNull("subAppid").replaceAll("\r|\n|\t", "");
        subMerchantId = p_xe.getSingleTextNotNull("subMerchantid").replaceAll("\r|\n|\t", "");
		merchantId = p_xe.getSingleTextNotNull("merchantId").replaceAll("\r|\n|\t", "");
        sellerId = p_xe.getSingleTextNotNull("sellerId").replaceAll("\r|\n|\t", "");
		virtualAct = p_xe.getSingleTextNotNull("virtualAct").replaceAll("\r|\n|\t", "");
		inMerchantId = p_xe.getSingleTextNotNull("inMerchantId").replaceAll("\r|\n|\t", "");
		resendURL = p_xe.getSingleTextNotNull("resendURL").replaceAll("\r|\n|\t", "");
		posNoticeUrl = p_xe.getSingleTextNotNull("posNoticeUrl").replaceAll("\r|\n|\t", "");
		termId = p_xe.getSingleTextNotNull("termId").replaceAll("\r|\n|\t", "");
		createIP = p_xe.getSingleTextNotNull("createIP").replaceAll("\r|\n|\t", "");
		batType = p_xe.getSingleTextNotNull("batType").replaceAll("\r|\n|\t", "");
        billType = p_xe.getSingleTextNotNull("billType").replaceAll("\r|\n|\t", "");
		billRequestType = p_xe.getSingleTextNotNull("billRequestType").replaceAll("\r|\n|\t", "");
		ownKeyStorePath = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("ownKeyStorePath")).replaceAll("\r|\n|\t", "");
		ownKeyPassword = p_xe.getSingleTextNotNull("ownKeyPassword").replaceAll("\r|\n|\t", "");
		ownCertFilePath = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("ownCertFilePath")).replaceAll("\r|\n|\t", "");
		oppCertFilePath = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("oppCertFilePath")).replaceAll("\r|\n|\t", "");
        alipayPublicCertPath = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("alipayPublicCertPath")).replaceAll("\r|\n|\t", "");
        rootCertPath = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("rootCertPath")).replaceAll("\r|\n|\t", "");
		identity = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("identity")).replaceAll("\r|\n|\t", "");
		saltKey = p_xe.getSingleTextNotNull("saltKey").replaceAll("\r|\n|\t", "");
        ArrayList<XElement> saltKeyList = p_xe.getChildList("saltKey");
        if (saltKeyList != null) {
            for (XElement c_xe : saltKeyList) {
                String p_for = c_xe.getAttrValue("for");
                saltKeyMap.put(p_for, c_xe.innerText);
            }
        }
		notifyURL = p_xe.getSingleTextNotNull("notifyURL").replaceAll("\r|\n|\t", "");
        ArrayList<XElement> notifyList = p_xe.getChildList("notifyURL");
        if (notifyList != null) {
            for (XElement c_xe : notifyList) {
                String p_for = c_xe.getAttrValue("for");
				notifyURLMap.put(p_for, c_xe.innerText);
            }
        }
		returnURL = p_xe.getSingleTextNotNull("returnURL").replaceAll("\r|\n|\t", "");
		bank = p_xe.getSingleTextNotNull("bank").replaceAll("\r|\n|\t", "");
		recAgNum = p_xe.getSingleTextNotNull("recAgNum").replaceAll("\r|\n|\t", "");
		appSecret = p_xe.getSingleTextNotNull("appSecret").replaceAll("\r|\n|\t", "");
		ArrayList<XElement> appSecretList = p_xe.getChildList("appSecret");
		if (appSecretList != null) {
			for (XElement c_xe : appSecretList) {
				String p_for = c_xe.getAttrValue("for");
				appSecretMap.put(p_for, c_xe.innerText);
			}
		}
		busCode = p_xe.getSingleTextNotNull("busCode").replaceAll("\r|\n|\t", "");
		ArrayList<XElement> arrayList = p_xe.getChildList("busCode");
		if (arrayList != null) {
			for (XElement c_xe : arrayList) {
				String p_for = c_xe.getAttrValue("for");
				if (!"".equals(p_for)) {
					busCodeMap.put(p_for, c_xe.innerText);
				}
			}
		}
		amtLimit = p_xe.getSingleTextNotNull("amtLimit").replaceAll("\r|\n|\t", "");
		ftpPath = p_xe.getSingleTextNotNull("ftpPath").replaceAll("\r|\n|\t", "");
		goodNo = p_xe.getSingleTextNotNull("goodNo").replaceAll("\r|\n|\t", "");
		refundNotifyURL = p_xe.getSingleTextNotNull("refundNotifyURL").replaceAll("\r|\n|\t", "");
		posRefundNotifyURL = p_xe.getSingleTextNotNull("posRefundNotifyURL").replaceAll("\r|\n|\t", "");
		pid = p_xe.getSingleTextNotNull("pid").replaceAll("\r|\n|\t", "");
		signType = p_xe.getSingleTextNotNull("signType").replaceAll("\r|\n|\t", "");
		ownKeyWebAPIStorePath = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("ownKeyWebAPIStorePath").replaceAll("\r|\n|\t", ""));
		oppCertWebAPIFilePath = com.fingard.dsp.DSPSet.replaceFilePath(p_xe.getSingleTextNotNull("oppCertWebAPIFilePath").replaceAll("\r|\n|\t", ""));
		webAPISercretKey = p_xe.getSingleTextNotNull("webAPISercretKey").replaceAll("\r|\n|\t", "");
		webAPINotifyUrl = p_xe.getSingleTextNotNull("webAPINotifyUrl").replaceAll("\r|\n|\t", "");
		appAuthToken = p_xe.getSingleTextNotNull("appAuthToken").replaceAll("\r|\n|\t", "");
		qryStatementURL = p_xe.getSingleTextNotNull("qryStatementURL").replaceAll("\r|\n|\t", "");
		appKey = p_xe.getSingleTextNotNull("appKey").replaceAll("\r|\n|\t", "");
	}

	public String getBusCode(String p_for) {
		if (p_for == null) {
			return null;
		} else if (busCodeMap.containsKey(p_for)) {
			return busCodeMap.get(p_for);
		}
		return null;
	}

	public String getNotifyURLMap(String p_for) {
		if (p_for == null) {
			return null;
		} else if (notifyURLMap.containsKey(p_for)) {
			return notifyURLMap.get(p_for);
		}
		return null;
	}
}
